package com.crane.common.core.dto;

import com.crane.common.core.exception.BasicErrorCode;
import com.crane.common.core.exception.ErrorCode;

import java.text.MessageFormat;
import java.util.List;

public class MultiNoTotalResponse <T> extends Response {

    private List<T> data;


    public static <T> MultiNoTotalResponse<T> of(List<T> data) {
        MultiNoTotalResponse<T> MultiNoTotalResponse = new MultiNoTotalResponse<>();
        MultiNoTotalResponse.setSuccess(true);
        MultiNoTotalResponse.setCode(BasicErrorCode.SERVER_SUCCESS.getErrCode());
        MultiNoTotalResponse.setData(data);
        return MultiNoTotalResponse;
    }

    public static MultiNoTotalResponse buildFailure(String errMessage) {
        MultiNoTotalResponse response = new MultiNoTotalResponse();
        response.setSuccess(false);
        response.setCode(BasicErrorCode.SYS_ERROR.getErrCode());
        response.setErrMsg(errMessage);
        return response;
    }

    public static MultiNoTotalResponse buildFailure(String errCode, String errMessage) {
        MultiNoTotalResponse response = new MultiNoTotalResponse();
        response.setSuccess(false);
        response.setCode(errCode);
        response.setErrMsg(errMessage);
        return response;
    }


    public static MultiNoTotalResponse buildFailure(ErrorCode errorCode) {
        MultiNoTotalResponse response = new MultiNoTotalResponse();
        response.setSuccess(false);
        response.setCode(errorCode.getErrCode());
        response.setErrMsg(errorCode.getErrDesc());
        return response;
    }

    public static MultiNoTotalResponse buildFailure(ErrorCode errorCode, Object... replacements) {
        MultiNoTotalResponse response = new MultiNoTotalResponse();
        response.setSuccess(false);
        response.setCode(errorCode.getErrCode());
        response.setErrMsg(MessageFormat.format(errorCode.getErrDesc(), replacements));
        return response;
    }


    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }
}
